package com.csthink.auditlog.annotation;

import com.csthink.auditlog.enums.ActionEnum;
import com.csthink.auditlog.enums.CallerEnum;
import com.csthink.auditlog.enums.CategoryEnum;

import java.lang.annotation.*;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
@Documented
public @interface AuditLogging {

    /**
     * pure String
     */
    CategoryEnum category() default CategoryEnum.UNKNOWN;

    /**
     * pure String
     */
    ActionEnum action() default ActionEnum.UNKNOWN;

    /**
     * pure String
     * @return
     */
    CallerEnum caller() default CallerEnum.UNKNOWN;

    /**
     * pure String
     */
    String subAction() default "";

    /**
     * spEL: It use complex expression:
     * 1. #{expr} will parsed by spEL;
     * 2. string outside #{} just string;
     * eg. detail = "AccountId is #{#id}" & id = "123"
     * will get value "AccountId is 123"
     */
    String detail() default "";

    /**
     * All spEL expression.
     */
    String accountId() default "";

    Change change() default @Change();

    /**
     * Following parameters is using for help construct other parameters.
     * They will not in log.
     */

    /**
     * Using for mapping. It is not part of audit log, but when some key(like
     * type, etc) need mapping to a readable string, it can help.
     *
     * All spEL expression.
     */
    String mapping() default "";

    /**
     * will parse before business logic.
     *
     * All spEL expression.
     */
    String before() default "";

    /**
     * will parse after business logic.
     *
     * All spEL expression.
     */
    String after() default "";

    /**
     * will parse this first, when:
     * true:
     *     calc and put audit log
     * false:
     *     pass
     */
    String condition() default "";
}
